<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Steering A Linear Array Example (k-Wave)</title>
	<link rel="stylesheet" href="kwavehelpstyle.css" type="text/css">
	<meta name="description" content="Steering A Linear Array Example.">
</head>

<body><div class="content">

<h1>Steering A Linear Array Example</h1>

<p>This example demonstrates how to use k-Wave to steer a tone burst from a linear array transducer in 2D. It builds on the <a href="example_tvsp_transducer_field_patterns.html">Simulating Transducer Field Patterns Example</a>.</p>

<p>
    <ul>
        <li><a href="matlab:edit([getkWavePath('examples') 'example_tvsp_steering_linear_array.m']);" target="_top">Open the file in the MATLAB Editor</a></li>
        <li><a href="matlab:run([getkWavePath('examples') 'example_tvsp_steering_linear_array']);" target="_top">Run the file in MATLAB</a></li>
    </ul>
</p>

<h2>Contents</h2>
<div>
	<ul>
        <li><a href="#heading2">Defining the linear array and input signal</a></li>
        <li><a href="#heading3">Running the simulation</a></li>
    </ul>
</div>	

<a name="heading2"></a>
<h2>Defining the linear array and input signal</h2>

<p>The source mask is defined by creating a binary mask with the desired source points set to 1.</p>

<pre class="codeinput">
<span class="comment">% define source mask for a linear transducer with an odd number of elements   </span>
num_elements = 21;      <span class="comment">% [grid points]</span>
x_offset = 25;          <span class="comment">% [grid points]</span>
source.p_mask = zeros(Nx, Ny);
start_index = Ny/2 - round(num_elements/2) + 1;
source.p_mask(x_offset, start_index:start_index + num_elements - 1) = 1;
</pre>

<p>The input signal to each element is then created using 
the function <code><a href="toneBurst.html">toneBurst</a></code> with a geometrically steered temporal offset that varies across the source.</p>

<pre class="codeinput">
<span class="comment">% define the properties of the tone burst used to drive the transducer</span>
sampling_freq = 1/kgrid.dt;     <span class="comment">% [Hz]</span>
steering_angle = 30;            <span class="comment">% [deg]</span>
element_spacing = dx;           <span class="comment">% [m]</span>
tone_burst_freq = 1e6;          <span class="comment">% [Hz]</span>
tone_burst_cycles = 8;

<span class="comment">% create an element index relative to the centre element of the transducer</span>
element_index = -(num_elements - 1)/2:(num_elements - 1)/2;

<span class="comment">% use geometric beam forming to calculate the tone burst offsets for each
% transducer element based on the element index</span>
tone_burst_offset = 40 + element_spacing * element_index * ...
    sin(steering_angle * pi/180) / (medium.sound_speed * kgrid.dt);

<span class="comment">% create the tone burst signals</span>
source.p = toneBurst(sampling_freq, tone_burst_freq, tone_burst_cycles, ...
    'SignalOffset', tone_burst_offset);
</pre>

<p>A plot of the input signals for each transducer element is shown below.</p>

<img vspace="5" hspace="5" src="images/example_tvsp_steering_linear_array_01.png" style="width:560px;height:420px;" alt="">  
    
<a name="heading3"></a>
<h2>Running the simulation</h2>

<p>Visualisations of the pressure field at two different times for steering angles of +30 and -20 degrees are shown below.</p>

<img vspace="5" hspace="5" src="images/example_tvsp_steering_linear_array_02.png" style="width:560px;height:420px;" alt="">  
<img vspace="5" hspace="5" src="images/example_tvsp_steering_linear_array_03.png" style="width:560px;height:420px;" alt="">

</div></body></html>